﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class MathUtil
{

    #region 二维向量计算
    public static float Distance(Vector2 a, Vector2 b)
    {
        float x = a.x - b.x;
        float y = a.y - b.y;
        return (float)Math.Sqrt(x * x + y * y);
    }

    public static float DistanceSqr(Vector2 a, Vector2 b)
    {
        float x = a.x - b.x;
        float y = a.y - b.y;
        return x * x + y * y;
    }
    #endregion

    #region 随机数
    static System.Random random = new System.Random();

    public static float Range(float lNum, float rNum)
    {
        if (lNum < rNum)
            return (float)random.NextDouble() * (rNum - lNum) + lNum;
        return (float)random.NextDouble() * (lNum - rNum) + rNum;
    }

    public static int Range(int min, int max)
    {
        return random.Next(min, max);
    }

    public static bool RandomBool()
    {
        return random.Next(0, 2) == 0;
    }
    #endregion
}
